using MicroMsg.Common.Utils;
using MicroMsg.Storage;
using System;
using System.Collections.Generic;
namespace MicroMsg.Scene.Voice
{
	public class DownloadVoiceContext : IContextBase
	{
		private const string TAG = "DownloadVoiceContext";
		public const int MAX_DOWNLOAD_PACK_SIZE = 65536;
		public const int STATUS_READY = 0;
		public const int STATUS_RECVING = 1;
		public const int STATUS_BLOCK_RECVING = 2;
		public const int STATUS_BLOCK_COMPLETE = 3;
		public const int STATUS_COMPLETE = 4;
		public const int STATUS_ERROR = 5;
		public int mStatus;
		public int mMsgSvrID;
		public string strTalker;
		public int mOffset;
		private Queue<MsgTrans> mVoiceMsgQueue;
		public DownloadVoiceContext(int MsgSvrID, string talker)
		{
			this.mMsgSvrID = MsgSvrID;
			this.strTalker = talker;
			this.mVoiceMsgQueue = new Queue<MsgTrans>();
		}
		public bool UpdateQueue(MsgTrans voiceinfo)
		{
			if (voiceinfo == null)
			{
				Log.smethod_5("DownloadVoiceContext", "invalid voiceinfo");
				return false;
			}
			bool flag = false;
			using (Queue<MsgTrans>.Enumerator enumerator = this.mVoiceMsgQueue.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					MsgTrans current = enumerator.get_Current();
					if (current.nMsgSvrID == voiceinfo.nMsgSvrID && current.strClientMsgId == voiceinfo.strClientMsgId)
					{
						flag = true;
						break;
					}
				}
			}
			if (!flag)
			{
				this.mVoiceMsgQueue.Enqueue(voiceinfo);
			}
			return true;
		}
		public void Enqueue(MsgTrans voiceinfo)
		{
			this.mVoiceMsgQueue.Enqueue(voiceinfo);
		}
		public MsgTrans Dequeue()
		{
			if (this.mVoiceMsgQueue.get_Count() == 0)
			{
				return null;
			}
			return this.mVoiceMsgQueue.Dequeue();
		}
		public MsgTrans GetCurrentVoiceBlock()
		{
			if (this.mVoiceMsgQueue.get_Count() == 0)
			{
				return null;
			}
			return this.mVoiceMsgQueue.Peek();
		}
		public bool isRunning()
		{
			if (this.mStatus != 1 && this.mStatus != 2)
			{
				if (this.mStatus != 3)
				{
					return false;
				}
			}
			return true;
		}
		public bool isBlockRunning()
		{
			return this.mStatus == 2;
		}
		public bool needToClean()
		{
			if (this.mStatus != 4)
			{
				if (this.mStatus != 5)
				{
					return false;
				}
			}
			return true;
		}
		public bool needToHandle()
		{
			return this.mStatus == 0;
		}
	}
}
